package app.modules.security.util.conversion;

import app.modules.common.annotation.ConvertFrom;
import app.modules.common.annotation.ConvertTo;
import app.modules.security.dto.web.function.WebFunctionDTO;
import jasmine.framework.common.util.CollectionUtil;
import jasmine.framework.common.util.MapperUtil;
import jasmine.security.rbac.model.SecFunction;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author mh.z
 */
public class FunctionConvertUtil {

    @ConvertFrom(SecFunction.class)
    @ConvertTo(WebFunctionDTO.class)
    public static WebFunctionDTO secFunction2WebFunctionDTO(SecFunction secFunction) {
        if (secFunction == null) {
            return null;
        }

        return MapperUtil.mapTo(secFunction, WebFunctionDTO.class);
    }

    @ConvertFrom(SecFunction.class)
    @ConvertTo(WebFunctionDTO.class)
    public static List<WebFunctionDTO> secFunction2WebFunctionDTO(Collection<SecFunction> secFunctions) {
        if (CollectionUtil.isEmpty(secFunctions)) {
            return Collections.emptyList();
        }

        return MapperUtil.mapToList(secFunctions, WebFunctionDTO.class);
    }

}
